package com.cdbkj.cloud.pos.http;


import com.androidyang.library.http.okhttp.HttpClient;
import com.androidyang.library.http.okhttp.listener.HttpClientHandler;
import com.cdbkj.cloud.pos.bean.Filed;
import com.cdbkj.cloud.pos.bean.JsonResult;
import com.cdbkj.cloud.pos.bean.RegInfoForm;

import java.util.HashMap;
import java.util.Map;


public class HttpRequest {

    /**
     * 获取HttpClient
     */
    public static HttpClient httpClient = HttpClient.getInstance()
            .setLogLevel(HttpClient.LogLevel.BODY)
            .setReturnType(JsonResult.class)
            .newBuilder().trustAllHosts().build();

    /**
     * 获取 his时间
     * @param target
     * @param handler
     */
    public static void hisTime(String target, HttpClientHandler handler,String userId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("userId",userId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.hisTime, target, handler);
    }

    /**
     * 获取 档案信息
     * @param target
     * @param handler
     */
    public static void patientInfo(String target, HttpClientHandler handler,String patientId,String userId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("patientId",patientId);
        bodyMap.put("userId",userId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.patientInfo, target, handler);
    }

    /**
     * 获取 挂号时间
     * @param target
     * @param handler
     */
    public static void regDate(String target, HttpClientHandler handler,String userId,String regTypeId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("userId",userId);
        bodyMap.put("regTypeId",regTypeId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.regDate, target, handler);
    }

    /**
     * 获取挂号类别
     * @param target
     * @param handler
     */
    public static void regType(String target, HttpClientHandler handler,String userId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("userId",userId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.regType, target, handler);
    }

    /**
     * 获取科室列表
     * @param target
     * @param handler
     */
    public static void deptList(String target, HttpClientHandler handler,String userId, String regDate,String regTypeId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("userId",userId);
        bodyMap.put("searchDate",regDate);
        bodyMap.put("regTypeId",regTypeId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.deptList, target, handler);
    }

    /**
     * 获取班次列表
     * @param target
     * @param handler
     */
    public static void scheduleList(String target, HttpClientHandler handler,String inCode,String userId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("inCode",inCode);
        bodyMap.put("userId",userId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.scheduleList, target, handler);
    }

    /**
     * 获取号源列表
     * @param target
     * @param handler
     */
    public static void doctorList(String target, HttpClientHandler handler,String userId,String regDate, String regTypeId,String departmentId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("userId", userId);
        bodyMap.put("searchDate", regDate);
        bodyMap.put("regTypeId", regTypeId);
        bodyMap.put("departmentId", departmentId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.doctorList, target, handler);
    }

    /**
     * 确认挂号
     * @param target
     * @param handler
     */
    public static void confirmReg(String target, HttpClientHandler handler, RegInfoForm form) {
        Map bodyMap = new HashMap();
        bodyMap.put("userId",form.getUserId());
        bodyMap.put("regDate",form.getRegDate());
        bodyMap.put("patientId",form.getPatientId());
        bodyMap.put("patientName",form.getPatientName());
        bodyMap.put("cardTypeId",form.getCardTypeId());
        bodyMap.put("cardNo",form.getCardNo());
        bodyMap.put("regTypeId",form.getRegTypeId());
        bodyMap.put("regType",form.getRegType());
        bodyMap.put("departmentId",form.getDepartmentId());
        bodyMap.put("departmentName",form.getDepartmentName());
        bodyMap.put("scheduleId",form.getScheduleId());
        bodyMap.put("clinicCode",form.getClinicCode());
        bodyMap.put("doctorId",form.getDoctorId());
        bodyMap.put("doctorName",form.getDoctorName());
        bodyMap.put("totalCost",form.getTotalCost());
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.confirmReg, target, handler);
    }

    /**
     * 处理挂号支付信息
     * @param target
     * @param handler
     */
    public static void modifyReg(String target, HttpClientHandler handler, String registerId,String patientId,String payModeName,String payTypeID,String posTransNo,String openBank,String openAccount) {
        Map bodyMap = new HashMap();
        bodyMap.put("registerId",registerId);
        bodyMap.put("patientId",patientId);
        bodyMap.put("payModeName",payModeName);
        bodyMap.put("payTypeID",payTypeID);
        bodyMap.put("posTransNo",posTransNo);
        bodyMap.put("openAccount",openAccount);
        bodyMap.put("openBank",openBank);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.modifyReg, target, handler);
    }

    /**
     * 处理挂号支付信息
     * @param target
     * @param handler
     */
    public static void modifyRegWithYb(String target, HttpClientHandler handler, String registerId,String patientId,String siOutput,String siInputInfo,String siPatientInfo) {
        Map bodyMap = new HashMap();
        bodyMap.put("registerId",registerId);
        bodyMap.put("patientId",patientId);
        bodyMap.put("siInputInfo",siInputInfo);
        bodyMap.put("siOutput",siOutput);
        bodyMap.put("siPatientInfo",siPatientInfo);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.modifyRegWithYb, target, handler);
    }

    /**
     * 更新处方退费状态
     * @param target
     * @param handler
     */
    public static void modifyRegRescissionStatus(String target, HttpClientHandler handler, String status, String registerId) {
        Map bodyMap = new HashMap();
        bodyMap.put("status", status);
        bodyMap.put("registerId", registerId);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.modifyRegRescissionStatus, target, handler);
    }

    public static void modifyRegOrderPayStatus(String target, HttpClientHandler handler, String orderNumber){
        Map bodyMap = new HashMap();
        bodyMap.put("orderNumber",orderNumber);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.modifyRegOrderPayStatus, target, handler);
    }

    /**
     * 获取代缴费挂号列表
     * @param target
     * @param handler
     */
    public static void unPayRegister(String target, HttpClientHandler handler,String patientId,String userId) {
        Map bodyMap = new HashMap();
        bodyMap.put("patientId",patientId);
        bodyMap.put("userId",userId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.unpayReg, target, handler);
    }


    /**
     * 获取待缴费 处方列表
     * @param target
     * @param handler
     */
    public static void prescriptionList(String target, HttpClientHandler handler,String registerNo,String patientId,String userId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("patientId",patientId);
        bodyMap.put("userId",userId);
        bodyMap.put("registerNo",registerNo);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.prescriptionList, target, handler);
    }

    /**
     * 获取处方详情
     * @param target
     * @param handler
     */
    public static void prescriptionItem(String target, HttpClientHandler handler,String prescriptionDate,String prescriptionSeq,String userId) {
        Map bodyMap = getCommonArgs();
        bodyMap.put("prescriptionDate",prescriptionDate);
        bodyMap.put("prescriptionSeq",prescriptionSeq);
        bodyMap.put("userId",userId);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.prescriptionItem, target, handler);
    }

    /**
     * 处理处方支付信息
     * @param target
     * @param handler
     */
    public static void modifyPrescription(String target, HttpClientHandler handler,
                                          String userId, String prescriptionSeq,String patientId,String cardTypeId,String cardNo,
                                          String payModeName,String payTypeID,String posTransNo,String openBank,String openAccount) {
        Map bodyMap = new HashMap();
        bodyMap.put("userId",userId);
        bodyMap.put("prescriptionSeq",prescriptionSeq);
        bodyMap.put("patientId",patientId);
        bodyMap.put("cardTypeId",cardTypeId);
        bodyMap.put("cardNo",cardNo);
        bodyMap.put("payModeName",payModeName);
        bodyMap.put("payTypeID",payTypeID);
        bodyMap.put("posTransNo",posTransNo);
        bodyMap.put("openAccount",openAccount);
        bodyMap.put("openBank",openBank);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.modifyPrescription, target, handler);
    }

    /**
     * 处理处方支付信息（医保）
     * @param target
     * @param handler
     */
    public static void modifyPrescriptionWithYb(String target, HttpClientHandler handler, String userId,
                                                String cardTypeId,String cardNo, String prescriptionSeq,
                                                String patientId,String siOutput,String siInputInfo,String fyzh,
                                                String ybjsbh,String fphm,
                                                String siPatientInfo) {
        Map bodyMap = new HashMap();
        bodyMap.put("userId",userId);
        bodyMap.put("prescriptionSeq",prescriptionSeq);
        bodyMap.put("cardTypeId",cardTypeId);
        bodyMap.put("cardNo",cardNo);
        bodyMap.put("patientId",patientId);
        bodyMap.put("siInputInfo",siInputInfo);
        bodyMap.put("siOutput",siOutput);

        bodyMap.put("fyzh",fyzh);
        bodyMap.put("ybjsbh",ybjsbh);
        bodyMap.put("fphm",fphm);

        bodyMap.put("siPatientInfo",siPatientInfo);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.modifyPrescriptionWithYb, target, handler);
    }

    public static void YBHttp(String target, HttpClientHandler handler,String regNo,String prescriptionSeq, String cardTypeId,String patientId,String sn,String info){
        Map bodyMap = new HashMap();
        bodyMap.put("info",info);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.yb_http+"/"+patientId+"/"+regNo+"/"+prescriptionSeq+"/"+cardTypeId+"/"+sn, target, handler);

    }
    /**
     * 更新处方退费状态
     * @param target
     * @param handler
     */
    public static void modifyPrescriptionRescissionStatus(String target, HttpClientHandler handler, String status, String prescriptionSeq) {
        Map bodyMap = new HashMap();
        bodyMap.put("status", status);
        bodyMap.put("prescriptionSeq", prescriptionSeq);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.modifyPrescriptionRescissionStatus, target, handler);
    }

    public static void addRegOrder(String target, HttpClientHandler handler, RegInfoForm form) {
        Map bodyMap = new HashMap();
        double tem = Double.parseDouble(form.getRegisterId());
        bodyMap.put("registerId",new Double(tem).longValue());
        bodyMap.put("userId",form.getUserId());
        bodyMap.put("regDate",form.getRegDate());
        bodyMap.put("patientId",form.getPatientId());
        bodyMap.put("patientName",form.getPatientName());
        bodyMap.put("cardTypeId",form.getCardTypeId());
        bodyMap.put("cardNo",form.getCardNo());
        bodyMap.put("regTypeId",form.getRegTypeId());
        bodyMap.put("regType",form.getRegType());
        bodyMap.put("departmentId",form.getDepartmentId());
        bodyMap.put("departmentName",form.getDepartmentName());
        bodyMap.put("scheduleId",form.getScheduleId());
        bodyMap.put("clinicCode",form.getClinicCode());
        bodyMap.put("doctorId",form.getDoctorId());
        bodyMap.put("doctorName",form.getDoctorName());
        bodyMap.put("totalCost",form.getTotalCost());
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.addRegOrder, target, handler);
    }

    public static void addPrescriptionOrder(String target, HttpClientHandler handler,String prescriptionSeq,String cardTypeId,String cardNo,String userId){
        Map bodyMap = new HashMap();
        bodyMap.put("prescriptionSeq",prescriptionSeq);
        bodyMap.put("cardTypeId",cardTypeId);
        bodyMap.put("cardNo",cardNo);
        bodyMap.put("userId",userId);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.addPrescriptionOrder, target, handler);
    }

    public static void modifyPrescriptionOrderPayStatus(String target, HttpClientHandler handler, String orderNumber){
        Map bodyMap = new HashMap();
        bodyMap.put("orderNumber",orderNumber);
        httpClient.new Request().setUrlArgs(bodyMap).post().request(HttpUrls.modifyPrescriptionOrderPayStatus, target, handler);
    }

    public static String getQRCodeUrl(String orderNumber,Double cost,String type){
        String url =  HttpUrls.QRCODE_PATH+"/"+ Filed.wx_app_id+"/"+orderNumber+"/"+new Double(cost*100).longValue()+"/"+type;
        return url;
    }

    public static void getWxOrderPayStatus(String target, HttpClientHandler handler,String orderNumber){
        String url = HttpUrls.wx_order_status_query + "/" + Filed.wx_app_id + "/" + orderNumber;
        httpClient.new Request().get().request(url, target, handler);
    }

    public static void refundWxOrder(String target, HttpClientHandler handler,String orderNumber,Double totalFee){
        String url = HttpUrls.wx_order_refund + "/" + Filed.wx_app_id + "/" + orderNumber + "/" + new Double(totalFee*100).longValue();
        httpClient.new Request().get().request(url, target, handler);
    }

    public static void getDeviceInfo(String target, HttpClientHandler handler,String sn){
        Map bodyMap = new HashMap();
        bodyMap.put("sn",sn);
        httpClient.new Request().setUrlArgs(bodyMap).get().request(HttpUrls.deviceInfo, target, handler);
    }

    public static Map getCommonArgs() {
        return new HashMap();
    }

}
